package com.brucekong.slm.controller.system;

import com.brucekong.slm.common.PageResult;
import com.brucekong.slm.common.Result;
import com.brucekong.slm.model.system.RoleDomain;
import com.brucekong.slm.service.system.RoleService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 系统控制类
 */
@RestController
@RequestMapping("/system")
@Slf4j
@Api(value = "系统模块", tags = "系统模块")
public class RoleController {

    @Autowired
    private RoleService roleService;
    private Result result = new Result();
    private PageResult pageResult = new PageResult();

    @GetMapping("/role")
    @SuppressWarnings("unchecked")
    @ApiOperation(value = "角色信息", notes = "获取当前用户下可以查看的所有角色信息", code = 200, produces = "application/json", responseContainer = "Map", response = PageResult.class)
    public PageResult judgeUsername(@RequestParam(name = "page", required = false, defaultValue = "1") int page,
                                    @RequestParam(name = "limit", required = false, defaultValue = "10") int limit) {
        log.info("/system/role");

        PageInfo<RoleDomain> systemDomainList = roleService.getRoles(page, limit);

        pageResult.setCode(0);
        pageResult.setMsg(null);
        pageResult.setSuccess(true);
        pageResult.setCount(systemDomainList.getTotal());
        pageResult.setData(systemDomainList.getList());
        return pageResult;
    }

}